//
//  PersonalSettingFeedbackView.m
//  ChatForHot
//
//  Created by wr on 2018/10/17.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "PersonalSettingFeedbackView.h"

@interface PersonalSettingFeedbackView ()<YYTextViewDelegate>

@property (nonatomic,strong) UIButton *HOTCHATsaveBtn;
@property (nonatomic,strong) UIView *HOTCHATbackview;
@property (nonatomic,strong) YYTextView *HOTCHATadviceTextView;
@property (nonatomic,strong) UILabel *HOTCHATnumLab;
@property (nonatomic,strong) UIImageView *HOTCHATlogoView;
@end

@implementation PersonalSettingFeedbackView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self HOTCHATdidInitialized];
    }
    return self;
}

- (void)HOTCHATdidInitialized {
    @weakify(self)
    self.backgroundColor = HOTCHATrgb(242, 242, 242);
    self.HOTCHATbackview = [[UIView alloc] init];
    self.HOTCHATbackview.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.HOTCHATbackview];
    
    self.HOTCHATadviceTextView = [[YYTextView alloc] init];
    self.HOTCHATadviceTextView.delegate = self;
    self.HOTCHATadviceTextView.textVerticalAlignment = YYTextVerticalAlignmentTop;
    self.HOTCHATadviceTextView.textContainerInset = UIEdgeInsetsMake(0, 0, 7.0, 0);
    self.HOTCHATadviceTextView.scrollEnabled = YES;
    self.HOTCHATadviceTextView.font = [UIFont systemFontOfSize:14];
    self.HOTCHATadviceTextView.textColor = HOTCHATrgb(51, 51, 51);
    self.HOTCHATadviceTextView.placeholderTextColor = HOTCHATrgb(179, 179, 179);
    self.HOTCHATadviceTextView.placeholderText = NSLocalizedString(@"profileHe3", nil);
    [self addSubview:self.HOTCHATadviceTextView];
    
    self.HOTCHATnumLab = [[UILabel alloc] init];
    self.HOTCHATnumLab.font = [UIFont systemFontOfSize:12];
    self.HOTCHATnumLab.textColor = HOTCHATrgb(102, 102, 102);
    self.HOTCHATnumLab.textAlignment = NSTextAlignmentRight;
    self.HOTCHATnumLab.text = @"200";
    [self addSubview:self.HOTCHATnumLab];
    
    self.HOTCHATsaveBtn = [[UIButton alloc]init];
    [self.HOTCHATsaveBtn setBackgroundImage:[[UIImage imageNamed:@"personal_iden_sav_n"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 15, 15, 15) resizingMode:(UIImageResizingModeStretch)] forState:UIControlStateNormal];
    [self.HOTCHATsaveBtn setBackgroundImage:[[UIImage imageNamed:@"personal_iden_sav_h"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 15, 15, 15) resizingMode:(UIImageResizingModeStretch)] forState:UIControlStateHighlighted];
    [self.HOTCHATsaveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.HOTCHATsaveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [self.HOTCHATsaveBtn setTitle:NSLocalizedString(@"SENDBUTTON", nil) forState:UIControlStateNormal];
    self.HOTCHATsaveBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [[self.HOTCHATsaveBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        @strongify(self)
        if (self.delegate && [self.delegate respondsToSelector:@selector(HOTCHATFeedback:)]) {
            [self.delegate HOTCHATFeedback:self.HOTCHATadviceTextView.text];
        }
    }];
    [self addSubview:self.HOTCHATsaveBtn];
    
    _HOTCHATlogoView = [[UIImageView alloc] init];
    _HOTCHATlogoView.image = [UIImage imageNamed:@"personal_feedback_textlogo"];
    [self addSubview:self.HOTCHATlogoView];
}

- (void)textViewDidChange:(YYTextView *)textView {
    self.HOTCHATnumLab.text = [NSString stringWithFormat:@"%zd",[textView.text HOTCHATleftCharWithmaxLength:200]];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.HOTCHATbackview mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(150);
        make.width.equalTo(self.mas_width);
    }];
    
    [self.HOTCHATadviceTextView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.HOTCHATbackview).with.insets(UIEdgeInsetsMake(15, 23, 50, 20));
    }];
    
    [self.HOTCHATsaveBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
        make.top.equalTo(self.HOTCHATbackview.mas_bottom).offset(15);
        make.height.mas_equalTo(45);
    }];
    
    [self.HOTCHATnumLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.HOTCHATbackview).offset(-13);
        make.right.equalTo(self.HOTCHATbackview).offset(-15);
        make.height.mas_equalTo(16);
    }];
    
    [self.HOTCHATlogoView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.HOTCHATadviceTextView).offset(6);;
        make.right.equalTo(self.HOTCHATadviceTextView.mas_left);
    }];
}
@end
